<?php 
defined('IN_TS') or die('Access Denied.');

include 'userinfo.php';

$page = isset($_GET['page']) ? intval($_GET['page']) : '1';
$url = tsUrl('user','duty',array('id'=>$strUser['userid'],'page'=>''));
$lstart = $page*15-15;

$arrDuty = $new['user']->findAll('duty','userid='.$strUser['userid'].' and status>-1','addtime desc',null,$lstart.',15');

$arr1 = 'userid='.$strUser['userid'].' and status=-1 and  endtime<>0 and endtime<'.time();
$hisDuty =  aac('duty')->find('duty',$arr1);
$arrCate = aac('duty')->findAll('duty_cate',null,'cateid asc');
foreach($arrDuty as $key => $item){
	$arrDuty[$key]['group'] =  aac('group')->getOneGroup($item['groupid']);
	$arrDuty[$key]['address'] = $arrDuty[$key]['group']['groupname'];
	if($item['image']){
		$arrDuty[$key]['image'] = explode(',',$item['image']);
	}
	//服务类型
	$arrCate= aac('duty')->find('duty_cate',array('cateid'=>$item['cateid']),'catename');
	$arrDuty[$key]['cate'] = $arrCate['catename'];
	//获取评论
	$arrComments = $new['user']->findAll ( 'duty_comment', array (
		'dutyid' => $item['dutyid']
	), 'addtime desc' );

	foreach ( $arrComments as $k => $v ) {
		$arrDuty[$key]['comment'] [] = $v;
		$arrDuty[$key]['comment'][$k]['content'] = tsDecode($v['content']);
		$arrDuty[$key]['comment'][$k] ['user'] = aac ( 'user' )->getOneUser ( $v ['userid'] );
	}

}


$arrArticle  = $new['user']->findAll('article',array(
	'userid'=>$strUser['userid'],
),'addtime desc');
$arrGroup = $new['user']->findAll('group','isplace>0','groupid asc');
$strCate= aac('duty')->findAll('duty_cate','','orderid asc');

$dutyNum = $new['user']->findCount('duty','userid='.$strUser['userid'].' and status=1');
$pageUrl = pagination($dutyNum, 15, $page, $url);
//获取上次的通勤时间
$lastDuty = aac('duty')->find('duty',array('userid'=>$strUser['userid'],'status'=>1));

$title = $strUser['username'].'的服务记录';
include template('duty');